﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Xml;
using System.Collections.Generic;



namespace GraphGear
{
    public class Node
    {
        int _id;
        string _name;


        public Node(int id, string name)
        {
            this._id = id;
            this._name = name;


        }
        public int Id { get { return _id; } }
        public string Name { get { return _name; } }

    }


    public class Edge
    {
        int _sn;   //source node
        int _tn;


        public Edge(int sn, int tn)
        {
            this._sn = sn;
            this._tn = tn;


        }
        public int Sn{ get { return _sn; } }
        public int Tn{ get { return _tn; } }

    }




    public class Utils
    {
        public static void XMLgen(List<Node> nodes, List<Edge> edges)
        {
            using (XmlWriter writer = XmlWriter.Create("C:/Users/bassy/Desktop/TeamProject/TeamProject/TeamProject/graph.xml"))
            {
                writer.WriteStartDocument();
                writer.WriteWhitespace("\n");
                writer.WriteStartElement("graph");

                writer.WriteAttributeString("title", "T");

                writer.WriteAttributeString("linecolor", "cccccc");
                writer.WriteAttributeString("viewmode", "display");


                writer.WriteAttributeString("bgcolor", "ffffff");
                writer.WriteAttributeString("width", "360");
                writer.WriteAttributeString("height", "400");


                foreach (Node uzlik in nodes)
                {

                    writer.WriteStartElement("node");

                    writer.WriteAttributeString("id", uzlik.Id.ToString());

                    writer.WriteAttributeString("text", uzlik.Name);
                    
                    writer.WriteEndElement();
                    writer.WriteWhitespace("\n");
                }


                foreach (Edge hrana in edges)
                {

                    writer.WriteStartElement("edge");

                    writer.WriteAttributeString("sourceNode", hrana.Sn.ToString());

                    writer.WriteAttributeString("targetNode", hrana.Tn.ToString());
                    writer.WriteAttributeString("label", "");
                    writer.WriteEndElement();
                    writer.WriteWhitespace("\n");
                }



                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
    }
 
}